import random

# 卡普雷尔黑洞
def a6174():
    a = random.randint(1000,9999)
    while a != 6174:
        b = list(str(a))
        b.sort()
        c = int(''.join(b))
        d = int(''.join(b)[::-1])
        a = d-c
    print(a)
a6174()
